using System.Collections.Generic;
using UnityEngine;

public class NPCbulletpool : MonoBehaviour
{
	public static NPCbulletpool instance;

	public List<bulletmove> enablelist;

	public List<bulletmove> disablelist;

	private bulletmove tempbullet;

	public bulletmove originalbullet;

	private bool haveshot;

	public float intervaltime;

	private float timeofdelshot;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
	}

	private void Update()
	{
		if (haveshot)
		{
			timeofdelshot += Time.deltaTime;
			if (timeofdelshot > intervaltime)
			{
				haveshot = false;
				timeofdelshot = 0f;
			}
		}
	}

	public bulletmove GetBullet()
	{
		if (haveshot)
		{
			return null;
		}
		if (disablelist.Count > 0)
		{
			tempbullet = disablelist[0];
			disablelist.RemoveAt(0);
			enablelist.Add(tempbullet);
			haveshot = true;
			return tempbullet;
		}
		if (GlobalInf.CurrentQuality < (Quality)101)
		{
			return null;
		}
		if (enablelist.Count > 30)
		{
			return null;
		}
		tempbullet = (UnityEngine.Object.Instantiate(originalbullet.gameObject) as GameObject).GetComponent<bulletmove>();
		enablelist.Add(tempbullet);
		haveshot = true;
		tempbullet.transform.parent = base.transform;
		return tempbullet;
	}

	public void RecycleBullet(bulletmove b)
	{
		enablelist.RemoveAt(enablelist.IndexOf(b));
		UnityVersionUtil.SetActiveRecursive(b.gameObject, state: false);
		disablelist.Add(b);
	}

	private void OnDestroy()
	{
		if (instance != null)
		{
			instance = null;
		}
	}
}
